package org.apache.mina.example.lily.service;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

public class ServerEncoder extends ProtocolEncoderAdapter{

	
	@Override
	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
		byte[]data = message.toString().getBytes();
		IoBuffer buffer = IoBuffer.allocate(data.length+4).putInt(data.length).put(data);
		buffer.flip();
		out.write(buffer);
	}

}
